<?php
namespace App\Libs\Mail;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/22
 * Time: 11:50
 */
use \App\Libs\Captcha\Algorithms\Numeric;
use \App\Libs\Cache\Redis;
use PHPMailer\PHPMailer\PHPMailer;
use App\Libs\Base\Config;
use App\Libs\Views\Json;
class Mail
{
    static $mailConfig;
    public static function mail163($to,$subject,$body){
        self::$mailConfig = Config::instance()->mailer['163'];
        $res = self::SendEmailFinal($to,$subject,$body);
        return $res;
    }


    public static function SendEmailFinal($to,$subject,$body){
        $mail = new PHPMailer();
        $mail->isSMTP();
        $mail->CharSet = "utf8";
        $mail->Host = self::$mailConfig['host'];
        $mail->SMTPAuth = true;
        $mail->Username = self::$mailConfig['username'];
        $mail->Password = self::$mailConfig['password'];  //授权码
        $mail->SMTPSecure = self::$mailConfig['smtp_secure'];// 使用ssl协议方式
        $mail->Port = self::$mailConfig['port'];
        $mail->setFrom(self::$mailConfig['username']);// 设置发件人信息，如邮件格式说明中的发件人，这里会显示为Mailer(xxxx@163.com），Mailer是当做名字显示
        $mail->addAddress($to,'BlankTK');// 设置收件人信息，如邮件格式说明中的收件人，这里会显示为Liang(yyyy@163.com)
        $mail->IsHTML(true);
        $mail->Subject = $subject;// 邮件标题
        $mail->Body = $body;// 邮件正文
        if(!$mail->send()){// 发送邮件
            return ['msg'=>$mail->ErrorInfo];
        }else{
            return TRUE;
        }
    }
}